package com.cykj.controller;

import com.cykj.service.ProjectService;
import com.cykj.util.ResponseDto;
import com.cykj.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    @RequestMapping("/getAllProject")
    public ResponseDto getAllProject(@RequestBody PageVo vo){
        return projectService.getAllProject(vo.getPageCurr(), vo.getPageSize());
    }
    @RequestMapping("/changeStatus")
    public ResponseDto changeStatus(int proStatus, int projectId) {
        if (proStatus == 2) {
            proStatus = 0;
        } else if (proStatus == 1) {
            proStatus = 1;
        }
        ResponseDto dto = projectService.changeStatus(proStatus, projectId);
        return dto;
    }
    @RequestMapping("/searchProjectInfo")
    public ResponseDto searchProjectInfo(String value, int pageCurr, int pageSize) {
        return projectService.searchProjectInfo(value, pageCurr, pageSize);
    }
    @RequestMapping("/getAllName")
    public ResponseDto getAllName(){
        return projectService.getAllName();
    }
    @RequestMapping("/commitDelete")

    public ResponseDto commitDelete(String checked) {
        try {
            return projectService.commitDelete(checked);
        } catch (Exception e) {
            return new ResponseDto(-1, "操作失败了", null);
        }
    }
    @RequestMapping("/lookInclude")
    public ResponseDto lookInclude(int id){
        return projectService.lookInclude(id);
    }
    @RequestMapping("/addProjectCommit")
    public ResponseDto addProjectCommit(String name, String fatherDepartId, String price, String details, String status){
        return projectService.addProjectCommit(name, fatherDepartId, price,details, status);
    }
    @RequestMapping("/alterInfo")
    public ResponseDto alterInfo(int projectId, String projectName, String projectPrice,String detailsName){
        return projectService.alterProject(projectId,projectName,projectPrice,detailsName);
    }
    @RequestMapping("/getDetailsName")
    public ResponseDto getDetailsName(int id){
        return projectService.getDetailsName(id);
    }
    @RequestMapping("/deleteRow")
    public ResponseDto deleteRow(int projectId){
        return projectService.deleteRow(projectId);
    }
    @RequestMapping("/borderPriceSearch")
    public ResponseDto borderPriceSearch(int minPrice,int maxPrice,int pageCurr, int pageSize){
        return projectService.borderPriceSearch(minPrice, maxPrice,pageCurr,pageSize);
    }
    @RequestMapping("/selectProjectByDetails")
    public ResponseDto selectProjectByDetails(String name) {
        return projectService.selectProjectByDetails(name);
    }
}
